﻿<UserControl x:Class="SourceControlMonitor.Views.RepositoriesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:AttachedCommandBehavior;assembly=Infrastructure"
             xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>
            <Storyboard x:Key="expandStoryboard">
                <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="1.3" Duration="0:0:0.2" />
                <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" To="1.3" Duration="0:0:0.2" />
            </Storyboard>
            <!-- This storyboard will make the image revert to its original size -->
            <Storyboard x:Key="shrinkStoryboard">
                <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="1" Duration="0:0:0.2" />
                <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" To="1" Duration="0:0:0.2" />
            </Storyboard>
            <DataTemplate x:Key="ItemTemplate">
                <TextBlock Text="{Binding}" Foreground="Black" />
            </DataTemplate>
            <DataTemplate x:Key="SelectedTemplate">
                <TextBlock Text="{Binding}" Foreground="Black" />
            </DataTemplate>
            <Style TargetType="{x:Type ListBoxItem}">
                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                <Setter Property="Opacity" Value="0.5" />
                <Setter Property="MaxHeight" Value="15" />
                <Setter Property="FontWeight" Value="Normal" />
                <Style.Triggers>
                    <EventTrigger RoutedEvent="Mouse.MouseEnter">
                        <EventTrigger.Actions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Duration="0:0:0.5" Storyboard.TargetProperty="MaxHeight" To="40"  />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger.Actions>
                    </EventTrigger>
                    <EventTrigger RoutedEvent="Mouse.MouseLeave">
                        <EventTrigger.Actions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Duration="0:0:0.1" Storyboard.TargetProperty="MaxHeight" To="15"  />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger.Actions>
                    </EventTrigger>
                    <Trigger Property="IsSelected" Value="True" >
                        <Trigger.Setters>
                            <Setter Property="FontWeight" Value="Bold" />
                            <Setter Property="Background" Value="Transparent" />
                            <Setter Property="Foreground" Value="Black" />
                            <Setter Property="Opacity" Value="1.0" />
                        </Trigger.Setters>
                    </Trigger>
                </Style.Triggers>
                <Style.Resources>
                    <!--SelectedItem with focus-->
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LemonChiffon" Opacity=".4"/>
                    <!--SelectedItem without focus-->
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" Opacity=".4"/>
                </Style.Resources>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal">
            <Button Command="{Binding OnAddClick}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="..\Resources\Database.png" Width="32" />
                    <TextBlock Text="Add"  VerticalAlignment="Center"/>
                </StackPanel>
            </Button>
        </StackPanel>
        <ListBox Grid.Row="1" ItemsSource="{Binding Repositories.View}" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border BorderBrush="LightBlue" BorderThickness="1" Background="White" HorizontalAlignment="Stretch">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Image Source="{Binding Type, Converter={StaticResource TypeToImageConverter}}" Width="24" Margin="0,0,8,0" />
                            <TextBlock Grid.Column="1" Text="{Binding Name}" FontStyle="Italic" Margin="0,0,8,0" VerticalAlignment="Center" />
                            <Image Source="..\Resources\Delete.png" Width="16" Margin="0,0,8,0" local:CommandBehavior.Event="MouseDown" 
                                    local:CommandBehavior.Command="{Binding OnDeleteClick}" Grid.Column="2">
                                <Image.Triggers>
                                    <EventTrigger RoutedEvent="Image.MouseEnter">
                                        <BeginStoryboard Storyboard="{StaticResource expandStoryboard}" />
                                    </EventTrigger>
                                    <EventTrigger RoutedEvent="Image.MouseLeave">
                                        <BeginStoryboard Storyboard="{StaticResource shrinkStoryboard}" />
                                    </EventTrigger>
                                </Image.Triggers>
                                <Image.RenderTransform>
                                    <ScaleTransform ScaleX="1" ScaleY="1"/>
                                </Image.RenderTransform>
                            </Image>
                            <Image Source="..\Resources\Edit.png" Width="16" Margin="0,0,8,0" local:CommandBehavior.Event="MouseDown" 
                                    local:CommandBehavior.Command="{Binding OnEditClick}" Grid.Column="3">
                                <Image.Triggers>
                                    <EventTrigger RoutedEvent="Image.MouseEnter">
                                        <BeginStoryboard Storyboard="{StaticResource expandStoryboard}" />
                                    </EventTrigger>
                                    <EventTrigger RoutedEvent="Image.MouseLeave">
                                        <BeginStoryboard Storyboard="{StaticResource shrinkStoryboard}" />
                                    </EventTrigger>
                                </Image.Triggers>
                                <Image.RenderTransform>
                                    <ScaleTransform ScaleX="1" ScaleY="1"/>
                                </Image.RenderTransform>
                            </Image>
                        </Grid>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</UserControl>
